package com.wnhz.work.jy.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;
import android.widget.Toast;

import com.wnhz.work.jy.BaseActivity;
import com.wnhz.work.jy.MyMain;
import com.wnhz.work.jy.R;

/**
 * ---支付成功
 */
public class SuccessPayActivity extends BaseActivity implements View.OnClickListener {
    private TextView title;
    private TextView tv_money;
    private TextView tv_pay_type;
    private TextView tv_beans_num;

    private String allprice;
    private String paytype;
    private String reward;
    private int type;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_success_pay);

        initData();
        initView();
    }

    private void initData() {
        allprice = getIntent().getStringExtra("allprice");
        paytype = getIntent().getStringExtra("paytype");
        reward = getIntent().getStringExtra("reward");
        type = getIntent().getIntExtra("type",-1);
    }

    private void initView() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("支付结果");
        findViewById(R.id.btn_main_left).setVisibility(View.GONE);
        findViewById(R.id.tv_back_home).setOnClickListener(this);

        tv_money = (TextView) findViewById(R.id.tv_money);
        tv_pay_type = (TextView) findViewById(R.id.tv_pay_type);
        tv_beans_num = (TextView) findViewById(R.id.tv_beans_num);

        tv_money.setText("¥ " + allprice);
        if ("5".equals(paytype)) {
            tv_pay_type.setText("余额");
        }else if ("1".equals(paytype)){
            tv_pay_type.setText("支付宝");
        }else {
            tv_pay_type.setText(paytype);
        }
        tv_beans_num.setText(reward);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {

            //返回首页
            case R.id.tv_back_home:
                Toast.makeText(SuccessPayActivity.this, "返回首页", Toast.LENGTH_SHORT).show();
                finish();
                break;

            default:
                break;
        }
    }

    @Override
    public void finish() {
        if (type == -1){
            Intent intent = new Intent(SuccessPayActivity.this, MyMain.class);
            intent.putExtra("Pagination", 3);
            startActivity(intent);
        }else {
            super.finish();
        }

    }
}
